/*
 * Copyright 2013 Wajdi Hh "wajdihh@gmail.com" .
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hh.ui.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.Button;
import android.widget.LinearLayout;

import com.hh.droid.R;
import com.hh.ui.view.DroidWriterView;

/**
 * 
 * A rich editText editor  contains different text style : bold , italic and classic with color selection
 * 
 * @author WajdiHh : Last modification : 23/05/2013
 *
 */
public class UiRicheEditText extends LinearLayout{

	private DroidWriterView _myEdMessage;
	private Button _myBtnTextColor,_myBtnTextBold,_myBtnTextItalic,_myBtnUnderLine;
	private Context _myContext;
	private LinearLayout _mLlColor;

	
	public UiRicheEditText(Context pContext, AttributeSet pAttributes) {
		super(pContext, pAttributes);
		_myContext=pContext;
	}

	@Override
	protected void onFinishInflate() {

		super.onFinishInflate();
		LayoutInflater lInflater = LayoutInflater.from(_myContext);
		lInflater.inflate(R.layout.ui_richetext, this);
		
		_myBtnTextColor = (Button) this.findViewById(R.id.BtnTextColor);
		_myBtnUnderLine= (Button) this.findViewById(R.id.BtnUnderLine);
		_myBtnTextBold = (Button) this.findViewById(R.id.BtnTextBold);
		_myBtnTextItalic = (Button) this.findViewById(R.id.BtnTextItalic);
		_mLlColor= (LinearLayout) findViewById(R.id.LinearTextColor);
		_myEdMessage=(DroidWriterView) this.findViewById(R.id.EdCorps);	
		
		_myEdMessage.setTextBoldButton(_myBtnTextBold);
		_myEdMessage.setTextItalicButton(_myBtnTextItalic);
		_myEdMessage.setTextUnderLineButton(_myBtnUnderLine);
		_myEdMessage.setButtonColor(_myBtnTextColor);
		_myEdMessage.setLinearColor(_mLlColor);
	}
	
	/**
	 * <br>
	 * Sets the text to be displayed when the text of the TextView is empty
	 * 
	 * @author WajdiHh
	 * @param pStringRes : resource ID of the String
	 */
	public void setHint(int pStringRes){
		_myEdMessage.setHint(getContext().getResources().getString(pStringRes));
	}
	
	/**
	 * <br>
	 * Sets the text to be displayed when the text of the TextView is empty
	 * 
	 * @author WajdiHh
	 * @param pString : chars sequences
	 */
	public void setHint(String pString){
		_myEdMessage.setHint(pString);
	}
	/**
	 * <br>
	 * sets height of the rich editText
	 * 
	 * @author WajdiHh
	 * @param pHeight : int : px
	 */
	public void setHeight(int pHeight){
		_myEdMessage.setHeight(pHeight);
	}
	/**
	 * <br>
	 * set width of the riche editText
	 * 
	 * @author WajdiHh
	 * @param pWidth : int px
	 */
	public void setWidth(int pWidth){
		_myEdMessage.setWidth(pWidth);
	}
	
	/**
	 * <br>
	 * return the text content displayed on the riche edittext
	 * 
	 * @author WajdiHh
	 * @return the text content 
	 */
	public String getText(){
		
		return _myEdMessage.getText().toString();
	}
	/**
	 * <br>
	 * return the HTML content format
	 * 
	 * @author WajdiHh
	 * @return the text HTML format 
	 */
	public String getTextHTML(){
		
		return _myEdMessage.getTextHTML();
	}
}

